﻿using System;
using System.Runtime.Serialization;
using System.Xml.Serialization;

namespace NMemcached.Client
{
    /// <summary>
    /// Represents the detailed information for a cache entry
    /// </summary>
    [Serializable]
    [DataContract(Name = "cacheDetail")]
    [XmlType(TypeName = "cacheDetail")]
    public class CacheDetail
    {
        /// <summary>
        /// Gets or sets the "check and set" unique value
        /// </summary>
        [DataMember(Name = "casUnique")]
        [XmlElement(ElementName = "casUnique")]
        public ulong CasUnique { get; set; }
        /// <summary>
        /// Gets or sets the key for the cache item
        /// </summary>
        [DataMember(Name = "key")]
        [XmlElement(ElementName = "key")]
        public string Key { get; set; }
        /// <summary>
        /// Gets or sets the opaque value for the cache operation
        /// </summary>
        [DataMember(Name = "opaque")]
        [XmlElement(ElementName = "opaque")]
        public ulong Opaque { get; set; }
        /// <summary>
        /// Gets or sets the value of the cache item
        /// </summary>
        [DataMember(Name = "value")]
        [XmlElement(ElementName = "value")]
        public object Value { get; set; }

        /// <summary>
        /// Initializes a new instance of the CacheDetail class
        /// </summary>
        public CacheDetail()
            : this(null, null, 0, 0)
        {
        }

        /// <summary>
        /// Initializes a new instance of the CacheDetail class
        /// </summary>
        /// <param name="key">The key of the cache item</param>
        public CacheDetail(string key)
            : this(key, null, 0, 0)
        {
        }

        /// <summary>
        /// Initializes a new instance of the CacheDetail class
        /// </summary>
        /// <param name="key">The key of the cache item</param>
        /// <param name="value">The value of the cache item</param>
        public CacheDetail(string key, object value)
            : this(key, value, 0, 0)
        {
        }

        /// <summary>
        /// Initializes a new instance of the CacheDetail class
        /// </summary>
        /// <param name="key">The key of the cache item</param>
        /// <param name="value">The value of the cache item</param>
        /// <param name="casUnique">The "check and set" uniqe value of the cache item</param>
        public CacheDetail(string key, object value, ulong casUnique)
            : this(key, value, casUnique, 0)
        {
        }

        /// <summary>
        /// Initializes a new instance of the CacheDetail class
        /// </summary>
        /// <param name="key">The key of the cache item</param>
        /// <param name="value">The value of the cache item</param>
        /// <param name="casUnique">The "check and set" uniqe value of the cache item</param>
        /// <param name="opaque">The opaqe value for the cache operation</param>
        public CacheDetail(string key, object value, ulong casUnique, ulong opaque)
        {
            this.Key = key;
            this.Value = value;
            this.CasUnique = casUnique;
            this.Opaque = opaque;
        }
    }
}
